-
-
Notifications
You must be signed in to change notification settings - Fork 266
resolve method can use dependency injection #520
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
resolve method can use dependency injection #520
Conversation
Just a few high level feelings, will do a detailed review at a later time:
|
ef86e0f
to
7c113cd
Compare
master:
This PR:
The observation here is: it's measurable. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The bindings are global (ResolveInfo, SelectFields), which means even after the resolve is done and are still bound and linger around => I don't think that's a good idea. I think this is a fundamental thing: those args are effectively local data and only make sense in that specific resolver and nowhere else.
Another thing / train of thought: whilst convenient, this only affects query/mutation resolvers, not field resolvers. But I dare not to add more complexity to the resolvers in general. But if within a field resolver one needs a dependency, one has to go back to I wonder if it would make sense to provide more direct access to the container? E.g. via a property But I'm not sure that's smart either. Containers aren't supposed to be passed around. |
the reason why I came up with this a final resolver will act more like a Laravel controller methods where it also possible to inject dependencies |
Okay I will change that, maybe that will give some more acceptable performance. |
And I too think the approach is right 👍 I don't think having the ability to auto-inject into field resolvers will do us any good in terms of performance. The biggest result I know/work with returns (worst case) ~1000 models and queries around 20 fields I think. That wouldn't fly :-) |
I am a big fan of this, it'd really help tidy up some queries and mutations my project has going on |
Random: being able to inject the request likely has uses – for example, I'm currently working with phpleague oauth and throttlelogins, both expect the request object a lot. |
@crissi is this ready for review? |
yes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some smaller adjustment requested, in general I'm onboard with this.
Would you also be up for updating the docs:
- changelog
- readme, also explaining that
Closure
result inSelectFields
but the difference also being that the depth can be customized this way
Please ping me once done
97638ef
to
7e10cdb
Compare
@mfn can you take a look again? |
3388c8a
to
ba853ef
Compare
I don't even need to take a look to know something's not right :-/ Can you please undo this formatting changes? |
Ok, sorry, same as the other PR. Please remove any changes you did to try to please StyleCI. It's still enabled, yes, but we actually only use php-cs fixer already. The reports from StyleCI are not required to be green for merging, so from that workflow side it's ok. It's just confusing as hell until it's completely removed. Sorry 🤷♀️ |
Did run composer fix-style, but apparently had the old phpcs config lying around so IT used that instead |
Running it again correctly, but I still get the same changes... The pipeline is an success, so does that mean the master did not have the phpcs fixes?! |
I think to fix this should be easy as just removing/reverting all the commits you made specifically for StyleCI |
2a36983
to
7b5e9a8
Compare
@mfn it should be ready for review now |
# Conflicts: # CHANGELOG.md # src/Support/Field.php
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great, thanks!
throw new AuthorizationError('Unauthorized'); | ||
} | ||
|
||
return call_user_func_array($resolver, $arguments); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not just calling the app()->call() directly in here?
return app()->call([ $this, 'resolve' ], [
'root' => $root,
'args' => $args,
'ctx' => $ctx,
'resolveInfo' => $arguments[3],
'selectFields' => $this->instanciateSelectFields($arguments),
]);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤷♀️
You can always try making a PR!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mfn I just notice this because I had implement this feature for auto injecting anything I pass in by myself, so on this PR I notice my solution wouldn't be needed anymore as I could just use this, however I solved it with just a few lines by calling app()->call() and this implementation is trying to do alot.... Which makes me wonder if I missed something.. Or my suggestion would be enough.. Would it work?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it work?
I can't say, didn't author it /cc @crissi
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
seems like it would bound to specific variable names instead of now where only the 3 first are required arguments and you can use what ever variable name there after as long as the Class name is correct.
*make resolve works more like the controller methods